package com.baidu.location;

import android.net.wifi.ScanResult;
import java.util.List;

public final class z
{
  public List a = null;
  private long c = 0L;
  private long d = 0L;
  private boolean e = false;

  public z(w paramw, List paramList, long paramLong)
  {
    this.c = paramLong;
    this.a = paramList;
    this.d = System.currentTimeMillis();
    k();
    ak.a(w.i(), j());
  }

  private String a(int paramInt)
  {
    if (a() <= 0)
      return null;
    StringBuffer localStringBuffer = new StringBuffer(512);
    String str1 = this.b.f();
    int k = this.a.size();
    if (k > paramInt)
      k = paramInt;
    while (true)
    {
      int i1;
      String str2;
      int l = 0;
      paramInt = 1;
      int j = 0;
      int i = 0;
      if (l < k)
      {
        if (((ScanResult)this.a.get(l)).level == 0)
          break label444;
        if (paramInt != 0)
        {
          localStringBuffer.append("&wf=");
          str2 = ((ScanResult)this.a.get(l)).BSSID.replace(":", "");
          localStringBuffer.append(str2);
          i1 = ((ScanResult)this.a.get(l)).level;
          paramInt = i1;
          if (i1 < 0)
            paramInt = -i1;
          localStringBuffer.append(String.format(";%d;", new Object[] { Integer.valueOf(paramInt) }));
          i += 1;
          if ((str1 == null) || (!(str1.equals(str2))))
            break label450;
        }
      }
      for (paramInt = i; ; paramInt = j)
      {
        i1 = 0;
        j = paramInt;
        paramInt = i1;
        while (true)
        {
          while (true)
            l += 1;
          localStringBuffer.append("|");
          str2 = ((ScanResult)this.a.get(l)).BSSID.replace(":", "");
          localStringBuffer.append(str2);
          int i2 = ((ScanResult)this.a.get(l)).level;
          i1 = i2;
          if (i2 < 0)
            i1 = -i2;
          localStringBuffer.append(String.format(";%d;", new Object[] { Integer.valueOf(i1) }));
          i += 1;
          if ((str1 != null) && (str1.equals(str2)))
          {
            j = i;
            continue;
            if (paramInt == 0)
            {
              new StringBuilder().append(str1).append(j);
              ak.e();
              localStringBuffer.append("&wf_n=" + j);
              localStringBuffer.append("&wf_st=");
              localStringBuffer.append(this.c);
              localStringBuffer.append("&wf_et=");
              localStringBuffer.append(this.d);
              if (j > 0)
                this.e = true;
              return localStringBuffer.toString();
            }
            label444: label450: return null;
          }
        }
      }
    }
  }

  private String j()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("wifi=");
    if (this.a == null)
      return localStringBuilder.toString();
    int i = 0;
    while (i < this.a.size())
    {
      int j = ((ScanResult)this.a.get(i)).level;
      localStringBuilder.append(((ScanResult)this.a.get(i)).BSSID.replace(":", ""));
      localStringBuilder.append(String.format(",%d;", new Object[] { Integer.valueOf(j) }));
      i += 1;
    }
    return localStringBuilder.toString();
  }

  private void k()
  {
    int j;
    if (a() <= 0);
    do
    {
      return;
      j = this.a.size() - 1;
      i = 1;
    }
    while ((j <= 0) || (i == 0));
    int k = 0;
    int i = 0;
    if (k < j)
    {
      if (((ScanResult)this.a.get(k)).level >= ((ScanResult)this.a.get(k + 1)).level)
        break label145;
      ScanResult localScanResult = (ScanResult)this.a.get(k + 1);
      this.a.set(k + 1, this.a.get(k));
      this.a.set(k, localScanResult);
      i = 1;
    }
    label145: 
    while (true)
      while (true)
      {
        while (true)
          k += 1;
        j -= 1;
      }
  }

  public final int a()
  {
    if (this.a == null)
      return 0;
    return this.a.size();
  }

  public final String b()
  {
    try
    {
      String str = a(ak.I);
      return str;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public final String c()
  {
    try
    {
      String str = a(15);
      return str;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public final String d()
  {
    StringBuffer localStringBuffer = new StringBuffer(512);
    localStringBuffer.append("wifi info:");
    if (a() <= 0)
      return localStringBuffer.toString();
    int i = this.a.size();
    int j = i;
    if (i > 10)
      j = 10;
    int k = 0;
    i = 1;
    if (k < j)
    {
      if (((ScanResult)this.a.get(k)).level != 0)
        if (i != 0)
        {
          localStringBuffer.append("wifi=");
          localStringBuffer.append(((ScanResult)this.a.get(k)).BSSID.replace(":", ""));
          localStringBuffer.append(String.format(";%d;", new Object[] { Integer.valueOf(((ScanResult)this.a.get(k)).level) }));
          i = 0;
        }
      while (true)
      {
        while (true)
          k += 1;
        localStringBuffer.append(";");
        localStringBuffer.append(((ScanResult)this.a.get(k)).BSSID.replace(":", ""));
        localStringBuffer.append(String.format(",%d;", new Object[] { Integer.valueOf(((ScanResult)this.a.get(k)).level) }));
      }
    }
    return localStringBuffer.toString();
  }

  public final int e()
  {
    int k = 0;
    int i = 0;
    while (true)
    {
      int j = k;
      if (i < a())
      {
        j = -((ScanResult)this.a.get(i)).level;
        if (j <= 0)
          break label38;
      }
      return j;
      label38: i += 1;
    }
  }

  public final boolean f()
  {
    return this.e;
  }

  public final boolean g()
  {
    return (System.currentTimeMillis() - this.d >= 3000L);
  }

  public final boolean h()
  {
    return (System.currentTimeMillis() - this.d >= 5000L);
  }

  public final boolean i()
  {
    return (System.currentTimeMillis() - this.c >= 3000L);
  }
}